package com.fit.pages.registration;

import java.util.List;

import org.apache.tapestry5.annotations.AfterRender;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.beaneditor.BeanModel;
import org.apache.tapestry5.grid.GridDataSource;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.services.AssetSource;
import org.apache.tapestry5.services.BeanModelSource;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;
import org.got5.tapestry5.jquery.internal.TableInformation;

import com.fit.dao.registration.LicencePlateDAO;
import com.fit.entities.LicencePlate;

public class BrowseRegistrations {

	// @SessionState
	// private IDataSource dataSource;

	@Property
	private LicencePlate registration;

	private List<LicencePlate> registrations;

	// @Inject
	// private ComponentResources resources;

	@Inject
	private LicencePlateDAO registrationDAO;

	@Inject
	private BeanModelSource beanModelSource;

	@Property
	private LicencePlate current;

	@SuppressWarnings("unchecked")
	private BeanModel model;

	@Inject
	private JavaScriptSupport js;

	@Inject
	private AssetSource as;

	public List<LicencePlate> getRegistrations() {
		registrations = registrationDAO.findAll();
		return registrations;
	}

	//
	// public List<Celebrity> getAllCelebrities() {
	// System.out.println("Getting all celebrities...");
	// return dataSource.getAllCelebrities();
	// }

	// @SuppressWarnings("unchecked")
	// public BeanModel getModel() {
	// this.model = beanModelSource.createDisplayModel(Celebrity.class,
	// resources.getMessages());
	// this.model.get("firstName").sortable(false);
	// return model;
	// }

	public JSONObject getOptions() {
		JSONObject json = new JSONObject("bJQueryUI", "true", "sDom",
				"TC<\"clear\">Rlfrtip");
		/*
		 * If you want the Export mechanism, please add these lines JSONObject
		 * dataTable = new JSONObject(); dataTable.put("sSwfPath",
		 * as.getContextAsset("dataTables/TableTools/swf/copy_cvs_xls_pdf.swf",
		 * null).toClientURL()); json.put("oTableTools", dataTable);
		 */
		return json;
	}

	@AfterRender
	public void addJsFile() {
		/*
		 * The dataTable js file is just here for the demo page. You do not have
		 * to include it in your page. The DataTable will do it for you
		 */
		js.importJavaScriptLibrary(as
				.getExpandedAsset("${assets.path}/components/datatables/jquery.dataTables.min.js"));
		js.importJavaScriptLibrary(as.getContextAsset(
				"ColVis/media/js/ColVis.js", null));
//		js.importJavaScriptLibrary(as.getContextAsset(
//				"dataTables/ColReorder/media/js/ColReorder.js", null));
		/*
		 * If you want the Export mechanism, please add these two lines
		 * js.importJavaScriptLibrary(
		 * as.getContextAsset("dataTables/TableTools/js/ZeroClipboard.js",
		 * null)); js.importJavaScriptLibrary(
		 * as.getContextAsset("dataTables/TableTools/js/TableTools.js", null));
		 */
	}

	public TableInformation getTableInformation() {
		return new TableInformation() {
			public String getTableSummary() {
				return "This is summary for this table";
			}

			public String getTableCaption() {
				return "DataTable Sample";
			}

			public String getTableCSS() {
				return "";
			}
		};
	}
}
